<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 网站管理 <span class="c-gray en">&gt;</span> 广告资源管理<span class="c-gray en">&gt;</span> 添加广告资源</nav>
	<div id="sectionContent" class="Hui-article">
		<article class="page-container">
			<div class="form form-horizontal" id="form-admin-add">
				<input type="hidden" id="parentId"/>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>投放人：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" class="input-text" id="adOwner" name="adOwner">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3">联系电话：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" class="input-text" id="adOwnerPhone" name="adOwnerPhone">
					</div>
				</div>
        <div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>广告位置：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<select class="select" id="advertLocation"></select>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>广告名称：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" class="input-text" id="adName" name="adName">
					</div>
				</div>
        <div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>广告ICON：</label>
					<div class="formControls col-xs-8 col-sm-9">
              <input type="file" id="advertIconFile" class="input-text"  name="advertIcon" allowexts="gif,jpeg,jpg,png,bmp" accept="image/*">
  						<input type="hidden" id="advertIcon">
					</div>
				</div>
        <div class="row cl">
					<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>资源地址：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" class="input-text" id="resUri" name="resUri">
					</div>
				</div>
				<div class="row cl">
					<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
						<input class="btn btn-primary" type="button" v-on:click="saveData()" value="&nbsp;&nbsp;提交&nbsp;&nbsp;" style="margin-right:30px;">
						<input class="btn" type="button" onclick="javascript:history.go(-1)" value="&nbsp;&nbsp;取消&nbsp;&nbsp;">
					</div>
				</div>
			</div>
		</article>
	</div>
  <script type="text/javascript">
			$(function(){
					$('#advertIconFile').bind('change',function(e){
							uplodFile();
					});
			});
			function uplodFile(){
					var formData = new FormData();
					var file = document.querySelector('[type=file]');
					formData.append('file', file.files[0]);
					$.ajax({
				          url: '/restful/cms/v1.0/common/ufile' ,
				          type: 'POST',
				          data: formData,
				          async: false,
				          cache: false,
				          contentType: false,
				          processData: false,
				          success: function (result) {
										 $('#advertIcon').val(result);
				          },
				          error: function (returndata) {
				              console.log(returndata);
				              alert('文件上传失败');
				          }
				     });
				}
  </script>
	<script>
    new Vue({
        el:'#sectionContent',
        http: authorization(),
        created:function(){
					this.$http.patch('/restful/cms/v1.0/adresource/adlocations').then((response) => {
							var content = responseObj(response).data;
							content.forEach(function(obj){
								$('#advertLocation').append("<option value='"+obj.code+"'>"+obj.desc+"</option>");
							});
					}).catch(function(response) {
							alert(errorMsg(response));
					});
        },
        methods:{
            backToList:function(){
                window.parent.location.href="#!view/cms/adresource/adresource-list.html?"+Math.random();
            },
            saveData:function(){
                var formData = {
                    adOwner:$('#adOwner').val(),
                    adOwnerPhone:$('#adOwnerPhone').val(),
										adName:$('#adName').val(),
                    advertIcon:$('#advertIcon').val(),
                    resUri:$('#resUri').val(),
                    advertLocation:$('#advertLocation option:selected') .val()
                };
                this.$http.post('/restful/cms/v1.0/adresource',formData).then((response) => {
                    this.backToList();
                }).catch(function(response) {
                    alert(errorMsg(response));
                });
            }
        }
    });
</script>
